package com.woniuxy.stage3demo.service.chenyxuanService.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.chenyuxuanBean.OptLogBean;
import com.woniuxy.stage3demo.bean.chenyuxuanBean.StaffBean;
import com.woniuxy.stage3demo.mapper.chenyuxuanMapper.OptLogMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.chenyxuanService.IOptService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional(readOnly = true)
@Service
public class IOptLogServiceImpl implements IOptService {
@Resource
    private OptLogMapper optLogMapper;

    /**
     * 添加日志
     * @param optLogBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int addOptLog(OptLogBean optLogBean,StaffBean staffBean) {
        return optLogMapper.addOptLog(optLogBean,staffBean);
    }

    /**
     * 分页查询日志信息
     * @param pageRequest
     * @param optLogBean
     * @return
     */
    @Override
    public PageInfo<OptLogBean> findAllOptLog(PageRequest pageRequest, OptLogBean optLogBean) {
        return PageHelper.startPage(pageRequest.getLimit(), pageRequest.getPageNum()).
                doSelectPageInfo(() -> optLogMapper.findAllOptLog(pageRequest, optLogBean));
    }

    /**
     * 根据使用这ID查询信息
     * @param id
     * @return
     */
    @Override
    public OptLogBean findOneOptLog(int id) {
        return optLogMapper.findOneOptLog(id);
    }

    /**
     * 修改日志方法
     * @param optLogBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateOptLog(OptLogBean optLogBean) {
        return optLogMapper.updateOptLog(optLogBean);
    }

    /**
     * 删除日志
     * @param id
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int deleteOpt(int id) {
        return optLogMapper.deleteOpt(id);
    }
}
